<template>
	<view class="order-history">
		<view class="card order-item" v-for="item in dataList" :key="item.id">
			<view class="title">
				{{item.merchantSubName}}
				<view><text>{{item.price}}</text>元</view>
			</view>
			<navigator :url="`orderDetails?content=${encodeURIComponent(JSON.stringify(item))}`" hover-class="none">
				<view class="order-info-box">
					<image :src="item.commodityDTOS[0].imageKey" mode="aspectFill" :draggable="false" />
					<view class="order-info-list">
						<view class="order-info-item">
							<view class="label">商品名称</view>
							{{item.commodityDTOS[0].name}}
						</view>
						<view class="order-info-item">
							<view class="label">数量</view>
							{{item.commodityDTOS[0].quantity}}
						</view>
						<view class="order-info-item">
							<view class="label">下单时间</view>
							{{item.createdTime}}
						</view>
						<view class="order-info-item">
							<view class="label">状态</view>
							{{statusList[item.status]}}
						</view>
					</view>
				</view>
			</navigator>
		</view>
		<uni-load-more :status="loadmore" />
	</view>
</template>

<script>
import { orderList } from '@/api/convenientServices'
	export default {
		data() {
			return {
				statusList:['未支付', '已支付', '已完成', '已取消', '退款中', '已退款', '退款申请审核中'],
				loadmore: 'loading',
				ifBottomRefresh: false,
				dataList: [], //数据
				total: null, //总条数
				page: {
					current: 1, //第几页
					size: 10, //显示多少条
				}
			}
		},
		methods: {
			getList() {
				this.loadmore = 'loading'
				orderList(this.page).then(res => {
					//请求接口成功之后，判断加载状态，处理数据	
					if (this.ifBottomRefresh) {
						this.dataList= this.dataList.concat(res.data.records)
					} else {
						this.dataList= res.data.records
					}
					this.ifBottomRefresh = false
					this.loadmore = this.dataList.length < res.data.total ? 'more' : 'noMore'
			
				})
			},
			refresh() {
				this.page.current = 1
				this.ifBottomRefresh = false
				this.getList()
			}
		},
		onLoad() {
			this.getList()
		},
		onPullDownRefresh() {
			this.refresh()
		},
		onReachBottom() {	
			this.page.current += 1
			// 没有更多数据之后 就不会在触底加载
			if (this.loadmore == 'noMore') return
			this.ifBottomRefresh = true
			this.getList() // 触底 拉取数据
		}
	}
</script>

<style lang="scss" scoped>
	.order-item {
		padding: 30rpx;
		.title {
			font-size: 26rpx;
			margin-bottom: 30rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;
			view {
				font-size: 18rpx;
				color: #FC0204;
				text {
					font-size: 26rpx;
				}
			}
		}
	}
	.order-info-box {
		display: flex;
		image {
			width: 150rpx;
			height: 150rpx;
		}
		.order-info-list {
			margin-left: 30rpx;
			.order-info-item {
				font-size: 24rpx;
				margin-top: 20rpx;
				.label {
					color: #888;
					display: inline-block;
					width: 4em;
					text-align-last: justify;
					margin-right: 38rpx;
				}
			}
		}
	}
</style>
